package com.leonzx.base.utils;

import com.leonzx.base.config.security.ShiroDbRealm;
import com.leonzx.base.entity.system.User;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @Author:梁亮
 * @Description:
 * @Date: 2018/6/14 9:53
 */
public class PermissionUtils {
    private static final Logger logger = LoggerFactory.getLogger(PermissionUtils.class);

    /**
     * 及时刷新权限，也就是清缓存
     *
     * @param reflashUser
     */
    public static void reflashPermission(User reflashUser) {
        //刷新shiro中的权限信息
        DefaultSecurityManager rsm = SpringContextHolder.getBean("securityManager");
        ShiroDbRealm shiroDbRealm = (ShiroDbRealm) rsm.getRealms().iterator().next();
        logger.info("刷新用户：【" + reflashUser.getUsername() + "】的权限");
        shiroDbRealm.clearCachedAuthorizationInfo(reflashUser);
    }
}